import http from '@/utils/http'
import type { LoginParams, LoginResponse } from './types'
import type { ApiResponse } from '@/utils/http'

/**
 * 用户认证API
 */
export class AuthApi {
	/**
	 * 用户登录
	 * @param data 登录参数
	 * @returns Promise<LoginResponse>
	 */
	static async login(data: LoginParams): Promise<ApiResponse<LoginResponse>> {
		const response = await http.post<ApiResponse<LoginResponse>>({
			url: '/sys/login',
			data,
			isToken: false,
			duplicateRequestValidation: true,
		})
		return response
	}

	/**
	 * 用户登出
	 * @returns Promise<any>
	 */
	static async logout(): Promise<ApiResponse<any>> {
		const response = await http.post<ApiResponse<any>>({
			url: '/sys/logout',
			duplicateRequestValidation: true,
		})
		return response
	}
}

// 为了向后兼容，保留原有的导出方式
export const login = AuthApi.login
export const logout = AuthApi.logout

// 默认导出
export default {
	// 认证相关
	auth: AuthApi,
}
